# coding=utf-8
from card_base import CardBase, fakeCardArray
from sgs.common.constants import cardType

class ShunShouQianYang(CardBase):
    name = '顺手牵羊'
    def __init__(self, id, color, point):
        CardBase.__init__(self, id, color, point, cardType.NON_DELAY_SKILL)
        
    def action(self, cond, src, args):
        while len(args) != 1:
            src.addCmd('BROKE_RULE', ['要牵谁的羊？'])
            cmd, args = src.requireCmd(cond, 'REQ_TARGET', respCmds=['SET_TARGET'])
        target = src.game.getUser(int(args[0]))
        if not target.cardList:
            src.addCmd('BROKE_RULE', ['目标无羊可牵!'])
            return
        target.addCmd('NOTICE', ['玩家%s对你使用了 顺手牵羊'%src.name])
        src.removeCard(self.id)
        cards= []
        for card in target.cardList.values():
            if cardType.isEquipCard(card.cardType):
                cards.extend(card.toArray())
            else:
                cards.extend(fakeCardArray(card.id, '手牌'))
        respCmd, respArgs =  src.requireCmd(cond, 'REQ_SET_CARD', args=cards, respCmds=['SET_CARD'])
        rmCard = target.cardList[int(respArgs[0])]
        target.removeCard(rmCard.id, toTrash=False)
        target.addCmd('NOTICE', ['玩家%s牵走了你的%s'%(src.name, '_'.join(rmCard.toArray()))])
        src.addCards([rmCard])